﻿Module Formatting

    Private Sub FormatGeneric(ByVal aDataGrid As DataGridView, ByVal ParamArray ShowColumns() As String)
        Dim i As Integer = 0

        For Each col As DataGridViewColumn In aDataGrid.Columns
            col.Visible = False
            col.DisplayIndex = aDataGrid.Columns.Count - 1
            'col.DisplayIndex = -1
        Next

        For Each col As String In ShowColumns
            aDataGrid.Columns(col).Visible = True
            aDataGrid.Columns(col).DisplayIndex = i
            aDataGrid.Columns(col).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            i += 1
        Next
    End Sub

    Public Sub SortDataGrid(ByVal dgAccounts As DataGridView, ByVal col As Integer)
        Dim sortOrder As System.ComponentModel.ListSortDirection
        Dim glyphOrder As SortOrder
        dgAccounts.Columns(col).SortMode = DataGridViewColumnSortMode.Programmatic
        With dgAccounts.Columns(col).HeaderCell
            If .SortGlyphDirection = Windows.Forms.SortOrder.Descending Then
                sortOrder = System.ComponentModel.ListSortDirection.Ascending
                glyphOrder = Windows.Forms.SortOrder.Ascending
            Else
                sortOrder = System.ComponentModel.ListSortDirection.Descending
                glyphOrder = Windows.Forms.SortOrder.Descending
            End If
            dgAccounts.Sort(dgAccounts.Columns(col), sortOrder)
            .SortGlyphDirection = glyphOrder
        End With
    End Sub

End Module
